﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VIA.Integration;
using VIA.Integration.LeadShine;
using VIA.Presentation;
using VIA.Presentation.Contracts;
using VIA.Project.Presentation.ViewModel.Inspection;
using VIA.SiMoJi.Domain.Electronics;
using VIA.SiMoJi.Presentation.ViewModel;

namespace VIA.SiMoJi.Presentation.View
{
    /// <summary>
    /// AxisDebugView.xaml 的交互逻辑
    /// </summary>
    //[View(typeof(IAxisDebugView))]
    public partial class AxisDebugView : IAxisDebugView
    {
        public AxisDebugView()
        {
            InitializeComponent();
        }

        private AxisDebugViewModel Model => this.GetViewModel<AxisDebugViewModel>();

        public DmcAxis Axis
        {
            get => this.GetViewModel<AxisDebugViewModel>().Axis;
            set => this.GetViewModel<AxisDebugViewModel>().Axis = value;
        }

        public IObject EditObject
        {
            get => this.GetViewModel<AxisDebugViewModel>().EditObject;
            set => this.GetViewModel<AxisDebugViewModel>().EditObject = value;
        }

        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.Title = Axis.Name;
        }

        private async void Bt_JogP_MouseUp(object sender, MouseButtonEventArgs e)
        {
            await Axis.PauseAsync();
        }

        private void Bt_JogP_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Axis.PostiveAsync();
        }

        private async void Bt_JogN_MouseUp(object sender, MouseButtonEventArgs e)
        {
            await Axis.PauseAsync();
        }

        private void Bt_JogN_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Axis.NegativeAsync();

        }

        private async void Bt_JogP_MouseLeave(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                await Axis.PauseAsync();
        }

        private async void Bt_JogN_MouseLeave(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
                await Axis.PauseAsync();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var bt = e.OriginalSource as Button;
            var position = bt?.DataContext as AxisPointParam;
            Model.Move(position);

        }
    }
}
